home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Grayscale Bitmap ƒ / Grayscale Bitmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  4.4 KB  |  154 lines  |  [TEXT/KAHL]

  1. /*
  2.     Grayscale Bitmap.c
  3.  
  4.     This file contains the calls to create a bitmap shape from scratch. It will create a 1 pixel high by 256 pixel gxWide grayscale bitmap.  
  5.     We will then scale the bitmap shape by 60 in the y direction. 
  6.     
  7.     NOTE:
  8.     • This file requires the following files to run correctly:
  9.         "graphics shell.c", "GraphicsDebugLibrary.c", "TransformLibrary.c".
  10.  
  11.     • For the best printing results, print this file in "landscape".
  12.     
  13.     
  14.     Change History:
  15.  
  16.        4/96    bob        Updated #includes to support changed GX Library names.
  17.                     Updated the note regarding the files needed to run.
  18.                     Updated the copyright date.
  19.  
  20.     ©1992 - 1996 Apple Computer, Inc.
  21.     All rights reserved.
  22. */
  23.  
  24. #include <events.h>
  25. #include <windows.h>
  26.  
  27. #include <GXErrors.h>
  28. #include "GraphicsLibraries.h"
  29. #include <GXEnvironment.h>
  30. #include "graphics shell.h"
  31.  
  32. //
  33. //      Set up the title and size of the window 
  34. //
  35. Str255         gWindowTitle = "\p Grayscale Bitmap ";
  36. Rect         gWindowQDRect  = {50, 20, 170, 345};
  37.  
  38. //
  39. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  40. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  41. //    With  gGraphicsHeapSize set to 60k, I had 7 free blocks left in the graphics gxHeap. Sounds good to me.
  42. //
  43. long        gGraphicsHeapSize = 60;
  44.  
  45.  
  46. gxShape     gBitShape;
  47.  
  48.  
  49. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  50.  
  51. void DoInitialization(gWindow)
  52. WindowPtr gWindow;
  53. {
  54.     char        bitImage[256];
  55.     gxBitmap    theBitmapData;
  56.     gxPoint        theBitmapPosition;
  57.     short        loop; 
  58.     gxColor        grayPixelColor;
  59.  
  60.     gxViewPort    windowViewPortParent;
  61.  
  62.     //
  63.     //    Get the gxViewPort that is attached to the window, and set the dither of this gxViewPort to 4.  Which
  64.     //    will mean that all objects that are drawn into window will be dithered at a dither level of 4.
  65.     //
  66.      windowViewPortParent = GXGetWindowViewPort(gWindow);
  67.     GXSetViewPortDither(windowViewPortParent, 4);
  68.  
  69.     //
  70.     //    Define gBitShape's starting position
  71.     //
  72.     theBitmapPosition.x = theBitmapPosition.y = ff(25);
  73.  
  74.     //
  75.     //    Define the gBitShape's structure. It will be a bitmap shape which is 1 pixel high and 256 pixels wide.
  76.     //    We will attach a gray color space below.
  77.     //
  78.     theBitmapData.image     = bitImage;
  79.     theBitmapData.width     = 256;
  80.     theBitmapData.height     = 1;
  81.       theBitmapData.rowBytes     = 256;
  82.     theBitmapData.pixelSize = 8;
  83.     theBitmapData.space     = gxNoSpace;
  84.     theBitmapData.set         = nil;
  85.     theBitmapData.profile     = nil;
  86.     
  87.     grayPixelColor.space = gxGraySpace;
  88.     grayPixelColor.profile = nil;
  89.     
  90.     gBitShape = GXNewBitmap (&theBitmapData, &theBitmapPosition);
  91.     GXSetShapeAttributes (gBitShape, gxMemoryShape);
  92.  
  93.     //
  94.     //    Create a gray pixel gxColor and change the value of the pixel within our bitmap shape. Starting with the first
  95.     //    pixel within our bitmap shape and moving to the right.
  96.     //
  97.     for (loop = 0; loop <= 255; ++loop) {
  98.         grayPixelColor.element.gray = (loop << 8);
  99.         GXSetShapePixel (gBitShape , loop, 0, &grayPixelColor, 0);
  100.     }  
  101.  
  102.     //
  103.     //    Scale our bitmap shape - gBitShape by 60 in the y direction. This will grow the height of the shape by 40.
  104.     //
  105.     GXScaleShape (gBitShape, fixed1, ff(60), theBitmapPosition.x, theBitmapPosition.y);
  106. }
  107.  
  108.  
  109. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  110.  
  111. void DoDraw(gWindow)
  112. WindowPtr gWindow;
  113. {
  114.     GXDrawShape (gBitShape);
  115. }
  116.  
  117.  
  118. /*------ DoDispose -------------------------------------------------------------------------------------*/
  119.  
  120. void DoDispose(gWindow)
  121. WindowPtr gWindow;
  122. {
  123.     /**  
  124.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  125.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  126.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  127.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  128.         can turn notices on in this file by setting gDebugging = TRUE (above).
  129.     **/
  130.     GXDisposeShape(gBitShape);  
  131.      GXDisposeShape(gWindowBoundsShape);  
  132.        DisposeWindow(gWindow);
  133. }
  134.     
  135.  
  136. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  137.  
  138. void DoIdle(gWindow)
  139. WindowPtr gWindow;
  140. {
  141. }
  142.  
  143.  
  144. /*------ DoClick ---------------------------------------------------------------------------------------*/
  145.  
  146. void DoClick( orgMouseLoc, theWindow )
  147. gxPoint        orgMouseLoc;
  148. WindowPtr     theWindow;
  149. {
  150. }
  151.  
  152.  
  153.  
  154.